﻿@model Alma.Models.ShopModel
@using System.Globalization
@{
    ViewContext.Controller.ViewBag.Breadcrumb.Enter("Mon profil", "Edit", "User", new { id = Session["UserId"] });
    ViewContext.Controller.ViewBag.Breadcrumb.Enter("Edition d'un magasin");

    var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
}
<div class="fullcol">

    <script type="text/javascript">
        var map = null;

        function LoadMap() {
            map = new Microsoft.Maps.Map(document.getElementById('bingMap'),
            {
                credentials: 'AkCZ5m1WEQHmCI_IGnizvsQwwuocz4MVzwE7AI5t7nO8yrqo-18MfLem2Jyq4F8p',
                enableClickableLogo: false,
                enableSearchLogo: false
            });
            
            var location = new Microsoft.Maps.Location(@Model.LocationX.ToString(CultureInfo.InvariantCulture),
                @Model.LocationY.ToString(CultureInfo.InvariantCulture));
            map.setView({ zoom: 16, center: location });

            map.entities.clear();
            var pushpinOptions = {draggable:true};
            var pushpin = new Microsoft.Maps.Pushpin(location, pushpinOptions); 
            
            pushpindragend= Microsoft.Maps.Events.addHandler(pushpin, 'dragend', function() {
            
                $("#newLocationX").val(pushpin.getLocation().latitude);
                $("#newLocationY").val(pushpin.getLocation().longitude);
                $("#useBing").attr('checked', false);

            });

            map.entities.push(pushpin); 
            

        }

        $(document).ready(function () {
            LoadMap();
        });

     </script>

    <div id="bingMapWrapper"><div id="bingMap"></div></div>
    <h1>Mon magasin</h1>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.ID_User)
        @Html.Hidden("newLocationX", @Model.LocationX);
        @Html.Hidden("newLocationY", @Model.LocationY);
        <dl>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Name)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Name)
                    @Html.ValidationMessageFor(model => model.Name)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Email)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Email)
                    @Html.ValidationMessageFor(model => model.Email)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Phone)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Phone)
                    @Html.ValidationMessageFor(model => model.Phone)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Fax)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Fax)
                    @Html.ValidationMessageFor(model => model.Fax)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Address)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Address)
                    @Html.ValidationMessageFor(model => model.Address)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Zipcode)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Zipcode)
                    @Html.ValidationMessageFor(model => model.Zipcode)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Town)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Town)
                    @Html.ValidationMessageFor(model => model.Town)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Country)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Country)
                    @Html.ValidationMessageFor(model => model.Country)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    @Html.LabelFor(model => model.Description)
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Description)
                    @Html.ValidationMessageFor(model => model.Description)
                </div>
            </dd>
            <dt>
                <div class="editor-label">
                    URL de l'image
                </div>
            </dt>
            <dd>
                <div class="editor-field">
                    @Html.EditorFor(model => model.ImgUrl)
                    @Html.ValidationMessageFor(model => model.ImgUrl)
                </div>
            </dd>
        </dl>
        <p>
            <input style="display:inline;" type="checkbox" id="useBing" name="useBing" checked="checked" value="true" />
            <label style="display:inline;" for="useBing">Déterminer automatiquement la position sur la carte</label>
            <br />
            <input type="submit" value="Modifier" />
        </p>
    }
            @Html.ActionLink("Voir", "Show", new { id = Model.ID }, null)
    <h2>
        Dans ce magasin</h2>
    <div class="boxes">
    @foreach (var product in Model.Products)
    {
        <div>
            @Html.ActionLink(product.Name, "Show", "Product", new { id = product.ID }, null) |
             @Html.ActionLink("Editer", "Edit", "Product", new { id = product.ID }, null) |
              @Html.ActionLink("Supprimer", "Delete", "Product", new { id = product.ID }, null)
            <img src="@Url.Content(product.ImgUrl)" alt="@product.ImgUrl" />
            <p>@product.Description</p>
        </div>
    }
    @Html.ActionLink("Nouveau produit", "Create", "Product", new { id = Model.ID }, null)
    </div>
</div>
